import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    meta: {
      title: "秋-管理",
      meta: {
        requireLogin: true
      }
    },
    component: Home
  },
  {
    path: '/',
    name: 'Login',
    meta: {
      title: "秋-登录页面"
    },
    component: () => import(
      '../views/Login.vue'
    )
  },
  // }, {
  //   path: "/register",
  //   name: "Register",
  //   meta: {
  //     title: "秋-注册页面"
  //   },
  //   component: () => import(
  //     '../views/Register.vue')

  // }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

/*路由守卫:门岗*/
router.beforeEach((to, from, next) => {
  // 判定权限:只有登录 才能访问home页面
  let isLogin = false/*假定未登录*/
  //
  if (to.meta.requireLogin && isLogin == false) {
    alert("当前无法访问! 请登录后重试!!")
    //不允许跳转,直接回到首页
    //参数:填写名称
    next("/")
    return
  }

  document.title = to.meta.title
  /*调用之后才能前往下一页面*/
  next()
})


export default router
